import server from '@/config/server'

const api = {
  uploadAttach: server.api().post('/dt-order/orAnnex/uploadAttach')
}

//fileData {url, name}
function uploadAttach(annexEnum, businessId, fileData) {
  let info = {
    annexEnum,
    businessId
  }
  if (Array.isArray(fileData)) {
    info.attaches = fileData.map((i) => {
      return { attachAddress: i.url, fileName: i.name }
    })
  } else {
    info.attach = { attachAddress: fileData.url, fileName: fileData.name }
  }
  return api.uploadAttach.fetch(info)
}

export default {
  uploadAttach
}
